/*
 * @Author: chenr 526963089@qq.com
 * @Date: 2023-02-13 16:02:36
 * @LastEditors: chenr 526963089@qq.com
 * @LastEditTime: 2023-02-16 15:26:29
 * @Description:【 mock示例 仅供开发环境测试使用 】
 */

import { defaultRequest } from '@/utils/request';
import type {
  CaptchaInterface,
  LoginParamsType,
  LoginHeaderType,
  LoginInterface,
  MenusInterface,
} from './types';
export enum SiteAPI {
  captcha = '/mock/user/captcha', // 图形验证码
  login = '/mock/user/login', // 登录
  logout = '/mock/user/logout', // 退出登录
  checkLogin = '/mock/user/checkLogin', // 验证登录
  menus = '/mock/user/menus', // 查询个人应用权限树
  page = '/mock/page/list', // 分页
  remove = '/mock/page/remove', // 分页
}

/* 图形验证码 */
export const getCaptcha = () => {
  return defaultRequest.get<CaptchaInterface>({
    url: SiteAPI.captcha,
  });
};

/* 登录 */
export const login = (
  params: LoginParamsType,
  headers?: LoginHeaderType | {}
) => {
  const _headers = {};
  headers ? Object.assign(_headers, headers) : null;
  return defaultRequest.post<LoginInterface>({
    headers: _headers,
    url: SiteAPI.login,
    data: { ...params },
  });
};

/**
 * @description: 刷新token 与登录接口一致
 * @param {LoginParamsType} params
 * @return {*}
 */
export const refreshToken = (params: LoginParamsType) => {
  return defaultRequest.post<LoginInterface>({
    url: SiteAPI.login,
    data: { ...params },
  });
};

/* 退出登录 */
export const logout = () => {
  return defaultRequest.post({
    url: SiteAPI.logout,
  });
};

/* 验证登录 */
export const checkLogin = () => {
  return defaultRequest.get({
    url: SiteAPI.checkLogin,
  });
};

/* 获取权限 */
export const getMenus = () => {
  return defaultRequest.get<MenusInterface[]>({
    url: SiteAPI.menus,
  });
};

/* 分页 */
export const page = (params: any) => {
  return defaultRequest.get({
    url: SiteAPI.page,
    params,
  });
};
